﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
        xmlns:Controls="clr-namespace:EX_NFC.FrontEnd.Windows.Controls"
        xmlns:View="clr-namespace:EX_NFC.FrontEnd.Windows.View"
        xmlns:Converters="clr-namespace:EX_NFC.FrontEnd.Windows.Converters"
        mc:Ignorable="d"
        x:Class="EX_NFC.FrontEnd.Windows.MainWindow"
        Title="{Binding WindowTitle}"
        WindowStartupLocation="CenterScreen"
        WindowState="Maximized"
        d:DesignWidth="1000"
        d:DesignHeight="1393">
    <Window.Resources>
        <Style x:Key="TextBlockStyleRed"
               TargetType="{x:Type TextBlock}"
               BasedOn="{StaticResource DefaultTextBlockStyle}">
            <Setter Property="FontWeight"
                    Value="Bold" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="Foreground"
                    Value="Red" />
        </Style>
        <Style x:Key="TextBlockStyleGreen"
               TargetType="{x:Type TextBlock}"
               BasedOn="{StaticResource DefaultTextBlockStyle}">
            <Setter Property="FontWeight"
                    Value="Bold" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="Foreground"
                    Value="#FF31CE11" />
        </Style>
        <Converters:NullToBoolConverter x:Key="NullToBoolConverter" />
    </Window.Resources>

    <Window.DataContext>
        <Binding Path="Main"
                 Source="{StaticResource Locator}" />
    </Window.DataContext>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <extToolkit:ChildWindow Caption="Error"
                                Width="500"
                                Height="400"
                                IsModal="True"
                                x:Name="ErrorWindow"
                                WindowStartupLocation="Center"
                                CloseButtonVisibility="Hidden"
                                FontFamily="Segoe UI Light"
                                FontSize="18.667"
                                WindowState="Closed">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <!-- ROW 0 -->
                <TextBlock Text="{Binding Source={StaticResource Localizer},Path=Localize.Application_Exception_Type}"
                           Grid.Column="0"
                           Grid.Row="0"
                           Style="{DynamicResource ContentTextStyle}"
                           Margin="{DynamicResource BasicMargin}"
                           HorizontalAlignment="Right" />
                <TextBlock Text="{Binding ExceptionType}"
                           Grid.Column="1"
                           Grid.Row="0"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           FontSize="13.333" />
                <!-- ROW 1 -->
                <TextBlock Text="{Binding Source={StaticResource Localizer},Path=Localize.Application_Exception_Message}"
                           Grid.Column="0"
                           Grid.Row="1"
                           Style="{DynamicResource ContentTextStyle}"
                           Margin="{DynamicResource BasicMargin}"
                           HorizontalAlignment="Right"
                           VerticalAlignment="Top" />
                <ScrollViewer Grid.Column="1"
                              Grid.Row="1"
                              FontSize="13.333"
                              BorderBrush="{DynamicResource TransparentWhiteBrush}">
                    <TextBlock Text="{Binding ExceptionMessage}"
                               Grid.Column="1"
                               Grid.Row="1"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Center"
                               FontSize="13.333"
                               TextWrapping="Wrap" />
                </ScrollViewer>
                <!-- ROW 2 -->
                <TextBlock Text="{Binding Source={StaticResource Localizer},Path=Localize.Application_Exception_Stacktrace}"
                           Grid.Column="0"
                           Grid.Row="2"
                           Style="{DynamicResource ContentTextStyle}"
                           Margin="{DynamicResource BasicMargin}"
                           HorizontalAlignment="Right"
                           VerticalAlignment="Top" />
                <ScrollViewer Grid.Column="1"
                              Grid.Row="2"
                              FontSize="13.333"
                              BorderBrush="{DynamicResource TransparentWhiteBrush}">
                    <ScrollViewer.Background>
                        <ImageBrush />
                    </ScrollViewer.Background>
                    <TextBlock Text="{Binding ExceptionStacktrace}"
                               HorizontalAlignment="Left"
                               ScrollViewer.CanContentScroll="True"
                               ScrollViewer.VerticalScrollBarVisibility="Auto"
                               TextWrapping="Wrap" />
                </ScrollViewer>

                <!-- ROW 3 -->
                <Button Content="{Binding Source={StaticResource Localizer},Path=Localize.OK}"
                        Command="{Binding CommandCloseExceptionWindow}"
                        Grid.Column="0"
                        Grid.ColumnSpan="2"
                        Grid.Row="3"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Margin="{DynamicResource BasicMargin}"
                        Width="{DynamicResource MediumControlWidth}"
                        Height="{DynamicResource MediumControlHeight}" />
            </Grid>

        </extToolkit:ChildWindow>
        <TabControl Grid.Row="1">
            <TabItem Header="{Binding Source={StaticResource Localizer},Path=Localize.Application_DeviceTab}">
                <extToolkit:BusyIndicator x:Name="BusyIndicatorDeviceItem"
                                          IsBusy="{Binding IsBusy}"
                                          BusyContent="{Binding BusyMessage}">
                    <Grid>
                        <GroupBox Header="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_ConnectionGroup}"
                                  Margin="8,8,0,0"
                                  Height="123"
                                  VerticalAlignment="Top"
                                  HorizontalAlignment="Left">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Port"
                                           Width="50"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Center"
                                           Margin="15,0,0,0"
                                           Style="{DynamicResource DefaultTextBlockStyle}" />
                                <ComboBox Margin="{DynamicResource BasicMargin}"
                                          Width="{DynamicResource MediumControlWidth}"
                                          Height="30"
                                          ItemsSource="{Binding Ports}"
                                          SelectedItem="{Binding SelectedPort,Mode=TwoWay}"
                                          SelectedIndex="2" />
                                <Button Content="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_Connect}"
                                        Margin="{DynamicResource BasicMargin}"
                                        Width="{DynamicResource MediumControlWidth}"
                                        Height="{DynamicResource MediumControlHeight}"
                                        Command="{Binding CommandConnect}"
                                        Visibility="{Binding IsDeviceConnected, Converter={StaticResource OppositeBoolToVisibilityConverter}}"
                                        Style="{DynamicResource ButtonBasicStyle}" />
                                <Button Content="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_Disconnect}"
                                        Margin="{DynamicResource BasicMargin}"
                                        Width="{DynamicResource MediumControlWidth}"
                                        Height="{DynamicResource MediumControlHeight}"
                                        Command="{Binding CommandDisconnect}"
                                        Visibility="{Binding IsDeviceConnected, Converter={StaticResource BoolToVisibilityConverter}}" />
                            </StackPanel>
                        </GroupBox>
                        <GroupBox Header="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_InfoGroup}"
                                  HorizontalAlignment="Stretch"
                                  Margin="449,8,8,0"
                                  Width="Auto"
                                  IsEnabled="{Binding IsDeviceConnected}"
                                  Height="123"
                                  VerticalAlignment="Top">
                            <StackPanel>
                                <Controls:DeviceInfoControl />
                            </StackPanel>
                        </GroupBox>
                        <GroupBox Header="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_LCDGroup}"
                                  VerticalAlignment="Stretch"
                                  Margin="251.737,243.28,8,145.16"
                                  Height="Auto"
                                  IsEnabled="{Binding LCDEnabled}">
                            <StackPanel>
                                <Controls:DeviceLCDControl />
                            </StackPanel>
                        </GroupBox>
                        <GroupBox Margin="251.737,135,8,0"
                                  VerticalAlignment="Top"
                                  Height="104.28"
                                  Header="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_BuzzerGroup}"
                                  IsEnabled="{Binding BuzzerEnabled}">
                            <Controls:DeviceBuzzerControl />
                        </GroupBox>
                        <GroupBox HorizontalAlignment="Left"
                                  Margin="8,135,0,145.16"
                                  Width="239.737"
                                  Header="{Binding Source={StaticResource Localizer},Path=Localize.DevicePage_LEDsGroup}"
                                  IsEnabled="{Binding LEDEnabled}">
                            <Controls:DeviceLEDControl />
                        </GroupBox>
                    </Grid>
                </extToolkit:BusyIndicator>
            </TabItem>
            <TabItem Header="{Binding Source={StaticResource Localizer},Path=Localize.Application_TagTab}"
                     IsEnabled="{Binding Mifare1K.Tag,Source={StaticResource Locator},Converter={StaticResource NullToBoolConverter}}">
                <View:Mifare1KView />
            </TabItem>
        </TabControl>
        <TextBlock HorizontalAlignment="Center"
                   TextWrapping="Wrap"
                   Text="EZ-NFC"
                   VerticalAlignment="Center"
                   Margin="0,0,0,30"
                   Style="{DynamicResource ApplicationNameStyle}"
                   FontSize="64"
                   FontWeight="Bold"
                   FontFamily="Segoe UI Semibold"
                   Foreground="#FF0084FF" />
        <StatusBar VerticalAlignment="Bottom">
            <StatusBarItem>
                <TextBlock x:Name="DeviceStatusText" />
            </StatusBarItem>
            <Separator />
            <StatusBarItem>
                <TextBlock x:Name="TagStatusText" />
            </StatusBarItem>
            <Separator />
            <StatusBarItem>
                <TextBlock x:Name="OperationStatusText" />
            </StatusBarItem>
            <Separator />
            <StatusBarItem HorizontalAlignment="Right">
                <TextBlock x:Name="ErrortatusText" />
            </StatusBarItem>
            <StatusBarItem HorizontalAlignment="Right">
                <Image x:Name="ErrorImage"
                       Source="" />
            </StatusBarItem>
        </StatusBar>
    </Grid>

</Window>
